home *** CD-ROM | disk | FTP | other *** search
/ Mac Magazin/MacEasy 19 / Mac Magazin and MacEasy Magazine CD - Issue 19.iso / Wissenschaft & Technik / chipmunk-basic-321 ƒ / chipmunk-basic quick-ref < prev    next >
Text File  |  1995-08-17  |  10KB  |  230 lines

  1. /*
  2.  * chipmunk-basic-3.2.x.sit.hqx
  3.  * Quick Reference and FAQ
  4.  
  5.  * Chipmunk Basic is (c) Copyright 1990,1994 Ronald H. Nicholson, Jr.
  6.  * ALL RIGHTS RESERVED
  7.  *
  8.  * This program is distributed in the hope that it will be useful, but
  9.  * WITHOUT ANY WARRANTY OF ANY KIND; not even the implied warranty of
  10.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11.  
  12. ---
  13. Quick Reference for Chipmunk Basic v3.2 - PPC Macintosh version 95Aug
  14. ported by Ronald H. Nicholson, Jr.    rhn@netcom.com
  15.  
  16. - The interpreter includes an dumb old fashioned line number based editor.
  17.     (enter a line, delete a line, edit one line at a time).
  18. - Line numbers are required.
  19. - The variable types are long floats, short integers and strings with a
  20.     maximum length of 254 characters.  Variable names can be up to 31
  21.     characters long and are case insensitive.
  22. - Math is done using the built-in double precision IEEE math. Trigonometric
  23.     functions are all in radians.
  24.     
  25. Operators, functions and statements include:
  26.  
  27.     + - * / ^ mod  and or xor not  > < >= <= <> =
  28.     sqr() log() exp() sin() cos() tan() atn()  pi
  29.     abs() sgn() int() rnd() peek() val() asc() len()
  30.     mid$() right$() left$() str$() chr$()
  31.     goto  if then else endif  gosub return  select case
  32.     for to step next  while wend
  33.     rem  let  dim data read restore   field$()
  34.     input print open for output append as close# load save
  35.     inkey$  input$ eof()  files  fgetbyte# fseek#
  36.     run stop end exit quit cont  renum  new clear  def fn
  37.     date$ time$ timer  push() pop  sound morse say  sub
  38.     cls gotoxy moveto lineto  graphics window scrn mouse()
  39.     home get htab vtab pos()  varptr peek() poke fre
  40.     
  41. ---
  42. Some Simple Examples:
  43.  
  44.   for i=1 to 10 : print i : next i
  45.  
  46.   c$ = a$ + b$            : rem string concatenation
  47.   a$ = inkey$            : rem inkey$ is non-blocking 
  48.   
  49.   load "sieve.bas"        : rem load TEXT file as a Basic program
  50.                   : rem file names should have .bas extension
  51.   
  52.   open "filename" for output as #1 : print #1, "hello world" : close #1 
  53.   
  54.   gotoxy 5,10 : print "here"        : rem text window (0,0 origin)
  55.   x = pos(0)                : rem text cursor horizontal location
  56.   y = pos(-1)                : rem vertical text cursor location
  57.   
  58.   graphics 0  : moveto 10,10 : lineto 110,80    : rem draw graphics line
  59.   
  60. ---
  61. Frequently Asked Questions:
  62.  
  63. Q: Is more documentation on learning how to program in the BASIC language?
  64. A: The language is mostly compatible with books on programming in the BASIC
  65.    language that were published between 1978 and 1988.  Since these are mostly
  66.    out of print, your best bet is to try your local public library.
  67.  
  68. Q: Is there any way to redirect print statements to the printer?
  69. A: No, there is no way to make this work with current MacOS printer drivers.
  70.    I recommend printing to a file, and then using SimpleText to print.
  71.  
  72. Q: Why can't I load a text file using the "Open" menu?
  73. A: Chipmunk Basic requires that Basic program file names end with a ".bas"
  74.    suffix. However, if you hold down the option key, it will try to open any
  75.    TEXT file.
  76.  
  77. Q: How do I make my own sprites?
  78. A: I use ResEdit (available from ftp.apple.com).  Just paste the new sprite
  79.    'ICN#' and 'cicn's into the resource fork of your Basic program.  Resource
  80.    ID's 128-148 are reserved for the Chipmunk Basic interpreter, so please use
  81.    a high resource ID number.  A 'cicn' resource must have a corresponding
  82.    'ICN#' resource in order for Chipmunk Basic to display it.
  83.    
  84. Q: Why can't I make my graphics window bigger?
  85.    If you have enough memory in your Mac, try increasing the Preferred Memory
  86.    requirements of Chipmunk Basic using the Finder Get Info dialog.  Also try
  87.    decreasing the number of colors in the Monitors Control Panel.
  88.  
  89. Q: Why won't this Microsoft QuickBasic program run? ...
  90. A: Chipmunk Basic was never intended to be exactly compatible with any other
  91.    commercial BAISC language product.  It does include most of the features of
  92.    ANSI BASIC language definition.  Many BASIC programs that are saved as an
  93.    ASCII text file and that don't use features of a specific computer system can
  94.    be easily ported to Chipmunk Basic.
  95.    
  96. Q: Can you send me a list of different peeks and pokes?
  97. A: Peeks and pokes don't have much use on current Mac Systems.  If you want to
  98.    live dangerously, you might want to get a copy of SysEqu.h or LoMem.h from
  99.    an old C or 68K assembly language programming package; but don't expect
  100.    anything you do to be compatible with newer MacOS System software.
  101.  
  102. Q: Is there a compiler for Chipmunk Basic?
  103. A: No, however there are several commercial Basic compilers on the market and
  104.    rumors of major new support for the BASIC language on the Mac comming next
  105.    year (1996 maybe,  I know Nothing ... ).
  106.  
  107. Q: What is the history of Chipmunk Basic?
  108. A: In March 1990, p2c, a pascal to c translator was posted to comp.source.misc
  109.    by David Gillespie.  One of the test input files was "basic.p".  I used the
  110.    c output file to learn about language interpreters and then ported the
  111.    resulting interpreter to my Mac 512KE and then to a PowerMac 7100.
  112.  
  113. ---
  114. Some experimental Chipmunk Basic graphics commands:
  115. * note: The graphics commands in version 3.x are beta test and may be buggy. *
  116.     
  117.     GRAPHICS 0                // show graphics window
  118.     graphics -1                // hide graphics window
  119.     graphics WINDOW x, y, width, height    // graphics window setup
  120.  
  121.     graphics MOVETO  x,y            // Move pen To x,y
  122.     graphics LINETO  x,y            // draw Line To x,y
  123.     graphics OVAL  x,y            // oval  x wide by y high
  124.     graphics DRAWTEXT  a$            // DrawText
  125.                         // use MOVETO to position
  126.     
  127.     graphics RECT  x1,y1,x2,y2        // FrameRect
  128.     graphics FILLRECT  x1,y1,x2,y2,pat#    // PaintRect
  129.     graphics OVAL  x1,y1,x2,y2        // FrameOval
  130.     graphics FILLOVAL  x1,y1,x2,y2,pat#    // PaintOval
  131.     graphics PENSETUP  xsize, ysize, [ mode, pat# ]
  132.     graphics COLOR  i            // set RGBForeColor by index
  133.     graphics COLOR  r,g,b            // red green blue 0-100
  134.  
  135.     graphics PICT  x,y,n            // draw 'pict' resource n
  136.     graphics TEXTSETUP f, s, m    // set up text font, size, mode
  137.  
  138.     graphics (-38)            // get graphics window max width
  139.     graphics (-39)            // get graphics window max height
  140.  
  141.     SPRITE    n  x, y, id        // sprite n @ x,y using ICN# or cicn id
  142.                     // n from 1 to 15, 1 in frontmost plane
  143.                     // ICN# 128 - 141 included with chipbasic
  144.                     // a cicn requires ICN# with same id.
  145.     sprite    n  UP    x        // sprite #n move up x pixels
  146.     sprite  n  DOWN  x        //   also returns new sprite y coord
  147.     sprite  n  LEFT  x        // move LEFT (not turn as in Logo!)
  148.     sprite  n  RIGHT   x
  149.     sprite    n  TURN    d        // turn CCW d degrees
  150.     sprite    n  FORWARD x        // move forward x pixels
  151.     sprite    n  PENUP
  152.     sprite    n  PENDOWN
  153.     sprite    n  COLLISION        // returns 1st sprite# in contact
  154.     
  155. ---
  156. Other unusual and/or experimental features:
  157.  
  158.       morse "CQ DE N6YWU",16,40,13,700    // play morse code
  159.       // MORSE string, dot_wpm, volume, letter_wpm, freq
  160.   
  161.     open "SFGetFile" for input as #2    // "SFPutFile" works for output
  162.     open "COM1:" for input as #3        //  *requires* CTB Serial Tool
  163.     open f$ for data input as #4    // data file, no cr<->lf translation
  164.     open f$ for data input        // opens resource file
  165.     say "hello world"        //  *requires* the Speech Manager & Lib
  166.     say "faster", 196, 44, 1        //  string, rate, pitch, voice #
  167.     a$ = field$("aa bb cc dd", 2, " ")  // "bb", similar to awk fields
  168.     sound 440,0.5,30            // freq, seconds_duration, vol 0-100
  169.     sound 0,8192                // play snd resource 8192
  170.     sound -1,a(0),11100        // play 1 sec. of samples from array a
  171.     sound n,freq(0),dur,vol(0)  // play n voices from arrays freq & vol
  172.     graphics WINDOW -1,-1, x,y, 2    // scroll graphics background to (x,y)
  173.     graphics BUTTON title$,x,y,w,h,key_code    // draw a standard button
  174.             // the button will input chr$(key_code) when pushed
  175.     graphics BUTTON "",x,y,id,key_code,-4    // using cicn or ICN# id
  176.     graphics EDIT a$ [,w,h]        // edit a$ in a text edit box
  177.     call n                // calls 68k assembly at address n
  178.     call "beep", i    // calls BCMD resource "beep" with 1 param (long *)i
  179.     call "doscript", appname$, doscript$    // send a DoScript AE
  180.     call "applescript", script$    // compiles and executes a script.
  181.                 // script$ can also be a string array.
  182.  
  183. A couple oddball commands included in version 3.2.0 just for testing:
  184.                 
  185.     call "fft_polar", real(0), amp(0), phase(0) , size  // size must = 2^n
  186.     call "fft_inv",   amp(0), phase(0), real(0) , size  // inverse fft
  187.  
  188.     call "math$", "mul$", r$, "1234567890", "9876543210"
  189.             // 250 digit string math (add$, sub$, mul$, div$, mod$)
  190.                 
  191.  
  192. - "Preferred Size" from Finder Get Info may limit maximum graphics window size
  193. - ICN#, cicn, PICT & BCMD resources may be stored the resource fork of a file:
  194.     open "foo.rsrc" for data input : rem with no "as" token,
  195.         // makes the file foo.rsrc the current resource file
  196. - bigfont options are stored in the Prefs file (edit w/ BBEdit or equiv.)
  197. - AppleScript scriptable. Try this script from a script editor:
  198.       tell application "chipbasic" to DoScript "print 3+4"
  199.       tell application "chipbasic" to DoScript "exec( \" 5 * 7 \" )"
  200.       
  201. ---
  202. Bugs or features:
  203.  
  204. - All input works like the LINE INPUT statement of other Basic versions.
  205. - Line numbers above 999999999 will not list.
  206. - Programs without line numbers can be loaded.  However line numbers will be
  207.     added.  The target of a GOTO can be a label followed by a colon.
  208.  
  209. ---
  210. A sample program:
  211.  
  212. --- cut here ---
  213. 1 rem "sieve.bas" , a prime number sieve benchmark
  214. 2 t = timer
  215. 3 dim f(8194)
  216. 4 for i = 0 to 8191 : f(i) = 1 : next i
  217. 5 s = 8191
  218. 6 for i = 0 to s
  219. 7   if f(i) = 0 then goto 11
  220. 8   p = i+i+3
  221. 9   for k = i+p to s step p : f(k) = 0 : next k
  222. 10   c = c+1
  223. 11 next i
  224. 12 print c;" primes found in ";
  225. 13 t = timer-t
  226. 14 print t;" seconds"
  227. 15 end
  228. --- cut here ---
  229.  */
  230.